clear
cd "C:\Users\selfd\Documents\autopartyinstitutionalization\legacy\cps\replication\data\stata"
use "C:\Users\selfd\Documents\autopartyinstitutionalization\legacy\cps\replication\data\stata\stata_replication.dta"
xtset ccode year

* Step 1: Create a matrix to store the results (coefficients and standard errors)
matrix results = J(10, 2, .)  // Create a 10x2 matrix to store coefficients and standard errors
local i = 1  // Initialize iteration counter

* Step 2: Loop through the 10 values of gwf_duration
forval i = 1/10 {
    * Run the regression with the specific value of gwf_duration
    xtpcse v2xps_party i.gwf_prior ib`i'.gwf_duration##c.pi1 prior_pi asp_dummy, pairwise
    
    * Step 3: Store the coefficient and panel-corrected standard error for pi1 in the matrix
    matrix results[`i', 1] = _b[pi1]  // Store coefficient in the first column
    matrix results[`i', 2] = _se[pi1] // Store standard error in the second column
}

matrix list results


* Step 4: Convert the matrix into a dataset
*clear
svmat results, names(col)

* Step 5: Save the dataset to a .dta file
save pi1_coefficients.dta, replace

*Switch to prior_pi
clear
use "C:\Users\selfd\Documents\autopartyinstitutionalization\legacy\cps\replication\data\stata\stata_replication.dta"
xtset ccode year

* Step 1: Create a matrix to store the results (coefficients and standard errors)
matrix results = J(10, 2, .)  // Create a 10x2 matrix to store coefficients and standard errors
local i = 1  // Initialize iteration counter

* Step 2: Loop through the 10 values of gwf_duration
forval i = 1/10 {
    * Run the regression with the specific value of gwf_duration
    xtpcse v2xps_party i.gwf_prior ib`i'.gwf_duration##c.prior_pi pi1 asp_dummy, pairwise
    
    * Step 3: Store the coefficient and panel-corrected standard error for pi1 in the matrix
    matrix results[`i', 1] = _b[prior_pi]  // Store coefficient in the first column
    matrix results[`i', 2] = _se[prior_pi] // Store standard error in the second column
}

matrix list results


* Step 4: Convert the matrix into a dataset
*clear
svmat results, names(col)

* Step 5: Save the dataset to a .dta file
save prior_pi_coefficients.dta, replace


*Switch to asp_dummy
clear
use "C:\Users\selfd\Documents\autopartyinstitutionalization\legacy\cps\replication\data\stata\stata_replication.dta"
xtset ccode year

* Step 1: Create a matrix to store the results (coefficients and standard errors)
matrix results = J(10, 2, .)  // Create a 10x2 matrix to store coefficients and standard errors
local i = 1  // Initialize iteration counter

* Step 2: Loop through the 10 values of gwf_duration
forval i = 1/10 {
    * Run the regression with the specific value of gwf_duration
    xtpcse v2xps_party i.gwf_prior ib`i'.gwf_duration##c.asp_dummy pi1 prior_pi, pairwise
    
    * Step 3: Store the coefficient and panel-corrected standard error for pi1 in the matrix
    matrix results[`i', 1] = _b[asp_dummy]  // Store coefficient in the first column
    matrix results[`i', 2] = _se[asp_dummy] // Store standard error in the second column
}

matrix list results


* Step 4: Convert the matrix into a dataset
*clear
svmat results, names(col)

* Step 5: Save the dataset to a .dta file
save asp_dummy_coefficients.dta, replace


*///////////////////////////////////////////////////////////////////////////
* repeat but drop asp_dummy
clear
use "C:\Users\selfd\Documents\autopartyinstitutionalization\legacy\cps\replication\data\stata\stata_replication.dta"
xtset ccode year

* Step 1: Create a matrix to store the results (coefficients and standard errors)
matrix results = J(10, 2, .)  // Create a 10x2 matrix to store coefficients and standard errors
local i = 1  // Initialize iteration counter

* Step 2: Loop through the 10 values of gwf_duration
forval i = 1/10 {
    * Run the regression with the specific value of gwf_duration
    xtpcse v2xps_party i.gwf_prior ib`i'.gwf_duration##c.pi1 prior_pi, pairwise
    
    * Step 3: Store the coefficient and panel-corrected standard error for pi1 in the matrix
    matrix results[`i', 1] = _b[pi1]  // Store coefficient in the first column
    matrix results[`i', 2] = _se[pi1] // Store standard error in the second column
}

matrix list results


* Step 4: Convert the matrix into a dataset
*clear
svmat results, names(col)

* Step 5: Save the dataset to a .dta file
save pi1_coefficients_noasp.dta, replace

*Switch to prior_pi
clear
use "C:\Users\selfd\Documents\autopartyinstitutionalization\legacy\cps\replication\data\stata\stata_replication.dta"
xtset ccode year

* Step 1: Create a matrix to store the results (coefficients and standard errors)
matrix results = J(10, 2, .)  // Create a 10x2 matrix to store coefficients and standard errors
local i = 1  // Initialize iteration counter

* Step 2: Loop through the 10 values of gwf_duration
forval i = 1/10 {
    * Run the regression with the specific value of gwf_duration
    xtpcse v2xps_party i.gwf_prior ib`i'.gwf_duration##c.prior_pi pi1, pairwise
    
    * Step 3: Store the coefficient and panel-corrected standard error for pi1 in the matrix
    matrix results[`i', 1] = _b[prior_pi]  // Store coefficient in the first column
    matrix results[`i', 2] = _se[prior_pi] // Store standard error in the second column
}

matrix list results


* Step 4: Convert the matrix into a dataset
*clear
svmat results, names(col)

* Step 5: Save the dataset to a .dta file
save prior_pi_coefficients_noasp.dta, replace